package com.leenleda.ips.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.leenleda.ips.R;
import com.leenleda.ips.databinding.DialogSettingBinding;
import com.leenleda.ips.receiver.Constant;
import com.leenleda.ips.util.LogUtils;

public class DialogSetting implements View.OnClickListener {
    private Dialog dialog;
    private OnClickListener listener;
    private DialogSettingBinding binding;
    /**
     * @param context
     */
    public DialogSetting(final Context context, OnClickListener onClickListener) {
        this.listener = onClickListener;
        binding = DialogSettingBinding.inflate(LayoutInflater.from(context));
        dialog = new Dialog(context, R.style.custom_dialog);// 创建自定义样式dialog

        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
//        params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE;
        params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        window.setAttributes(params);
        window.setGravity(Gravity.CENTER);

        dialog.setCancelable(true);// 可以用“返回键”取消
        dialog.setCanceledOnTouchOutside(true);// 设置点击屏幕Dialog不消失
        dialog.setContentView(binding.getRoot(), new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));// 设置布局

        binding.dialogIp.setOnClickListener(this);
        binding.dialogChange.setOnClickListener(this);
        binding.dialogClear.setOnClickListener(this);
        binding.dialogBack.setOnClickListener(this);
    }

    public void show() {
//        binding.dialogChange.setText(Constant.APP_TEST ? "正式页面" : "测试页面");
        binding.dialogChange.setText(Constant.APP_TEST ? "返回信发" : "功能测试");
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    public void dismiss() {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dialog_ip:
                listener.onClick(1);
                LogUtils.e("onClick", "---dialog_ip--------");
                break;
            case R.id.dialog_change:
                listener.onClick(2);
                LogUtils.e("onClick", "---dialog_id--------");
                break;
            case R.id.dialog_clear:
                listener.onClick(3);
                LogUtils.e("onClick", "---dialog_clear--------");
                break;
            case R.id.dialog_back:
                listener.onClick(4);
                LogUtils.e("onClick", "---dialog_back--------");
                break;
        }
    }

    public interface OnClickListener {
        void onClick(int state);//点击列表监听
//        void onTextChange();
    }

}
